package com.ms.game.itembox.db;

import com.ms.game.itembox.AccountItemChangeWay;
import com.ms.game.itembox.ItemStatus;
import com.ms.game.itembox.container.ItemBasic;
import com.ms.player.Player;
import com.ms.service.error.ErrorCode;
import com.xpec.c4.service.module.common.ItemInfoManager;
import com.xpec.c4.service.module.task.TaskAsyncCommand;

public class UpdateAccountItemStatusAsync extends TaskAsyncCommand{
	
	private int errorCode;
	
	private Player player;
	
	private String itemSn;
	
	private String orderId;
	
	private String itemId;

	@Override
	public void asyncExecute() throws Exception {
		
		
		ItemStatus from = ItemStatus.IS_PICKING;
		ItemStatus to = null;
		
		if(errorCode == ErrorCode.SUCCESS){
			to = ItemStatus.COUNT_ZERO;
		} else {
			to = ItemStatus.NORMAL;
		}
		
		int result = ItemDAO.changeAccountItemStatus(player.getAccountId().toString(), itemSn, from, to);
		if(errorCode == ErrorCode.SUCCESS){
			//成功要寫log		
		
			AccountItemModel model = ItemDAO.getAccountItemModel(itemSn);
			if(model!= null){
				ItemBasic item = ItemInfoManager.getInstance().getItem(model.getItemId());
				//拼湊log
				AccountItemChangeLogModel logModel = ItemDAO.makeAccountItemChangeLogModel(orderId.toString(), player.getAccountId().toString(), player.getGuid().toString(), 
						player.getNameWithNumber(), player.getUserType(), 
						itemSn, item.getItemId(), item.getName(), 1, 1, 0, 
						AccountItemChangeWay.SUB_ADD_TO_CHARACTOR, player.getZoneId(), player.getZoneId(), null , null, null);
				
				getModuleServer().saveDbLog(logModel);
			}

		}

	}

	@Override
	public void execute() throws Exception {
		
	}

	public int getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public Player getPlayer() {
		return player;
	}

	public void setPlayer(Player player) {
		this.player = player;
	}

	public String getItemSn() {
		return itemSn;
	}

	public void setItemSn(String itemSn) {
		this.itemSn = itemSn;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getItemId() {
		return itemId;
	}

	public void setItemId(String itemId) {
		this.itemId = itemId;
	}

}
